<template>
  <div>
    <a-button :style="{ marginBottom: '1rem' }" type="primary" @click="handleAddMessage"> 新增</a-button>
    <a-card :bordered="false" class="card-area">
      <a-table
        :pagination="ipagination"
        :loading="loading"
        rowKey="patientId"
        :columns="pushColumns"
        :data-source="push"
        :scroll="{ x: 1070 }"
        @change="handleTableChange"
      >
        <a slot="action" slot-scope="text, record">
          <template v-if="!record.applyStatus">
            <span style="color:rgba(0, 0, 0, 0.35);margin-right:10px;visibility: hidden;">已应用</span>
            <a-popconfirm placement="topLeft" ok-text="确定" cancel-text="取消" @confirm="handleApply(record)">
              <template slot="title">
                <p>是否确定应用？</p>
              </template>
              <a-button>应用</a-button>
            </a-popconfirm>
          </template>
          <template v-else>
            <span style="color:rgba(0, 0, 0, 0.35);margin-right:10px">已应用</span>
            <a-popconfirm
              v-if="record.applyStatus"
              placement="topLeft"
              ok-text="确定"
              cancel-text="取消"
              @confirm="handleApply(record)"
            >
              <template slot="title">
                <p>是否确定取消应用？</p>
              </template>
              <a-button>取消应用</a-button>
            </a-popconfirm>
          </template>
          <a-popconfirm placement="topLeft" ok-text="确定" cancel-text="取消" @confirm="handleDelete(record.dataId)">
            <template slot="title">
              <p>是否确定删除？</p>
            </template>
            <a-button style="margin-left:10px">删除</a-button>
          </a-popconfirm>
        </a>
      </a-table>
    </a-card>
    <team-doctor-modal ref="handleDoctor" @ok="handleSubmitOk"></team-doctor-modal>
  </div>
</template>

<script>
import { PAGE_MENU_TYPE } from '@/store/mutation-types'
import { getAction, postAction, deleteAction } from '@/api/manage'
import { axios } from '@/utils/request'
import signMd5Utils from '@/utils/encryption/signMd5Utils'
import JSelectPatientTag from '@/components/jeecgbiz/JSelectPatientTag'
import TeamDoctorModal from './drawer/TeamDoctorModal'
import moment from 'moment'

const pushColumns = [
  {
    title: '机构',
    dataIndex: 'orgName',
    width: 100
  },
  {
    title: '推送内容',
    dataIndex: 'orgPushMessage'
  },
  {
    title: '关联商品/服务包',
    dataIndex: 'orgProductName',
    width: 150
  },
  {
    title: '操作',
    key: 'operation',
    width: 300,
    fixed: 'right',
    scopedSlots: { customRender: 'action' }
  }
]

export default {
  components: { JSelectPatientTag, TeamDoctorModal },
  data() {
    return {
      loading: false,
      /* 分页参数 */
      ipagination: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '20', '30'],
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条'
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
      },
      groupParams: {
        orgCode: 'A01',
        actId: 120802
      },
      doctorQueryUrl: '/201/02/2010213',
      doctorParams: {
        pageNum: 1,
        pageSize: 10
      },
      pushColumns,
      push: [
        {
          orgName: '荔湾',
          orgPushMessage: 'tuisong',
          orgProduct: '逆转服务',
          dataId: 1
        },
        {
          orgName: '第一人民医院',
          orgPushMessage: 'tuisong',
          orgProduct: '逆转服务',
          dataId: 2
        },
        {
          orgName: '79医疗',
          orgPushMessage: 'tuisong',
          orgProduct: '逆转服务',
          dataId: 3
        }
      ],
      result: [],
      visible: false,
      confirmLoading: false,
      addParams: {},
      deletePatientInfoVisible: false,
      deleteDoctorUrl: '/201/02/2010203',
      modifyFrozen: '/201/02/2010211',
      modifyApprove: '/201/02/2010212'
    }
  },
  created() {
    this.getMessage()
  },
  methods: {
    getMessage() {
      // this.selectedRowKeys = []
      this.loading = true
      postAction('pushmessage/list', {})
        .then(res => {
          if (res.success) {
            this.push = res.result
            // if (res.result.total) {
            //   this.ipagination.total = res.result.total
            // } else {
            //   this.ipagination.total = 0
            // }
          }
        })
        .finally(() => {
          this.loading = false
        })
    },
    handleDelete(id) {
      deleteAction('pushmessage/delete', { id }).then(res => {
        if (res.success) {
          this.$message.success(res.message)
        } else {
          this.$message.error(res.message)
        }
        this.getMessage()
      })
    },
    handleApply(record) {
      postAction('pushmessage/edit', { ...record, applyStatus: !record.applyStatus }).then(res => {
        if (res.success) {
          this.$message.success(res.message)
        } else {
          this.$message.error(res.message)
        }
        this.getMessage()
      })
    },
    handleTableChange(pagination) {
      this.ipagination = pagination
      this.doctorParams.pageNum = pagination.current
      this.doctorParams.pageSize = pagination.pageSize
      this.getMessage()
    },
    handleAddMessage() {
      this.$refs.handleDoctor.add({})
      this.$refs.handleDoctor.title = '新增'
    },
    handleSubmitOk() {
      this.getMessage()
    }
  }
}
</script>

<style lang="less" scoped>
.ant-btn {
  margin: 0.2rem;
}

.flup-item {
  margin: 1rem;
  padding: 0.5rem;
  display: flex;
  align-items: center;

  span {
    flex: 1;
  }
}

#tip {
  display: block;

  #warning {
    // margin: 0.3rem;
    text-align: right;
  }
}

.it_search {
  background: white;
  border-top-left-radius: 2px;
  border-top-right-radius: 2px;
  padding: 10px 20px;
  color: rgba(0, 0, 0, 0.85);
}

.it_search > div {
  margin-bottom: 10px;
}

.ant-tag {
  font-size: 14px;
  border: 1px solid rgba(0, 0, 0, 0.65);
  margin-bottom: 5px;
}
.ant-tag-checkable-checked {
  border: 1px solid #f5222d;
}
/deep/.searchClass > .ant-form-item-control-wrapper {
  width: 150px;
}
</style>

